﻿import Vuex from 'vuex'
import Vue from 'vue'

Vue.use(Vuex)

const actions = {
    jia(context,value){
        context.mutations('JIA',value)
    },
    jian(context,value){
        context.mutations('JIAN',value)
    },

}

const mutations = {
    JIA(state,value){
        state.sum += value
    },
    JIAN(state,value){
        state.sum -= value
    },
    ADD_PERSON(state,value){
        state.personList.unshift(value)
    }
}

const state = {
    sum:0,
    school:'bilibili',
    subject: 'Vue',
    personList:[
        {id:'001',name:'张三'}
    ]
}

//准备getters:用于将state中的数据进行加工
const getters = {
    //给你要实现运算的值取一个名字
    bigSum(state){ //能接收到state的值
        return state.sum*10//跟计算属性类似:靠返回值来决定自己的值
    }
}

export default new Vuex.Store({
    actions,mutations,state,
    getters
})